--by grey

function DrawLine3D(x1,y1,z1,x2,y2,z2,linesize, linecolor)
    x1,y1 = get2DFrom3D(x1,y1,z1)
    x2,y2 = get2DFrom3D(x2,y2,z2)
    DrawLine(x1,y1,x2,y2,linesize or 1,linecolor or 4294967295)
end

function DrawHitBox(object, linesize, linecolor)
    local linesize, linecolor = linesize or 1, linecolor or 4294967295
    if object and object.minBBox then
        local x1,y1, onscreen = get2DFrom3D(object.minBBox.x,object.minBBox.y,object.minBBox.z)
        if onscreen then
            local x2,y2 = get2DFrom3D(object.minBBox.x,object.minBBox.y,object.maxBBox.z)
            local x3,y3 = get2DFrom3D(object.maxBBox.x,object.minBBox.y,object.maxBBox.z)
            local x4,y4 = get2DFrom3D(object.maxBBox.x,object.minBBox.y,object.minBBox.z)
            local x5,y5 = get2DFrom3D(object.minBBox.x,object.maxBBox.y,object.minBBox.z)
            local x6,y6 = get2DFrom3D(object.minBBox.x,object.maxBBox.y,object.maxBBox.z)
            local x7,y7 = get2DFrom3D(object.maxBBox.x,object.maxBBox.y,object.maxBBox.z)
            local x8,y8 = get2DFrom3D(object.maxBBox.x,object.maxBBox.y,object.minBBox.z)

            DrawLine(x1,y1,x2,y2,linesize,linecolor)
            DrawLine(x2,y2,x3,y3,linesize,linecolor)
            DrawLine(x3,y3,x4,y4,linesize,linecolor)
            DrawLine(x4,y4,x1,y1,linesize,linecolor)

            DrawLine(x1,y1,x5,y5,linesize,linecolor)
            DrawLine(x2,y2,x6,y6,linesize,linecolor)
            DrawLine(x3,y3,x7,y7,linesize,linecolor)
            DrawLine(x4,y4,x8,y8,linesize,linecolor)

            DrawLine(x5,y5,x6,y6,linesize,linecolor)
            DrawLine(x6,y6,x7,y7,linesize,linecolor)
            DrawLine(x7,y7,x8,y8,linesize,linecolor)
            DrawLine(x8,y8,x5,y5,linesize,linecolor)
        end
    end
end

table.getn = function(args)
    if type(args) == "table" then
        local count = 0
        for k, v in pairs(args) do
            count = count + 1
        end
        return count
    elseif type(args)=="number" then return #args
    end
end

table.insert = function(args, content)
   if type(args)=="table" then
       for i=1, table.getn(args) + 1, 1 do
           if args[i] == nil then args[i]=content break end
       end
   end
end
function math.round(num, idp)
    local idp=idp or 0
    local num = num*10^idp
    local upper=math.ceil(num)
    local lower=upper-1
    if num>0 then
        if num-lower>=0.5 then return upper/10^idp
        else return lower/10^idp end
    else
        if num-lower>0.5 then return upper/10^idp
        else return lower/10^idp end
    end
end

function table.copy(from)
    if type(from) == "table" then
    local to = {}
    for k, v in pairs(from) do
        to[k] = v
    end
    return to
end
end

function toString(...)
    local t=""
    for i,object in ipairs(arg) do
    if type(object) == "string" or type(object) == "number" then t=t..object
    elseif type(object) == "table" then
        t=t.."{ "
        for k,v in pairs(object) do
            if type(k)=="string" then t = t..toString(k).." = " end
            t=t..toString(v)..", "
        end
        t=t.."}"
    elseif type(object) == "function" then t = t.."function"
    end
    t=t.." "
    end
    return t
end